package code.snippet

import net.liftweb.http.StatefulSnippet
import net.liftweb.common.Loggable
import xml.NodeSeq
import net.liftweb.util.Helpers
import Helpers._
import code.model.{Homepage, Product}
import org.apache.commons.lang3.StringEscapeUtils
import code.util.WebUtil


/**
 * Created by IntelliJ IDEA.
 * User: cgeheran
 * Date: 4/15/12
 * Time: 5:55 PM
 * To change this template use File | Settings | File Templates.
 */

class ProductSnippet extends StatefulSnippet with Loggable with WebUtil {
  def dispatch = {
    case "getHomepageProducts" => getHomepageProducts _
  }

  def getHomepageProducts(in: NodeSeq): NodeSeq = {
    val homepageProducts = Homepage.products
    val css = "#product *" #> homepageProducts.map(p => ((".title *" #> p.title) & ((".description *") #> htmlEntityDecode(p.longDesc.asHtml.toString())) & (".image *" #> p.productImageSrc)))

    css(in)
  }


  //getProductsInCategory


}